Private Sub cmdTryCatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTryCatch.Click
    Dim lngFileSize As Long
    Dim intLoopCtr As Integer
    Dim intBufferCount As Integer
    Dim strInByte As String
    'Set the length of the strInbyte string
    strInByte = Space(256)
    ' If the destination file exists, ask the user if they
    ' want to continue
    If Dir(txtTargetFile.Text) <> "" Then
        If MsgBox(txtTargetFile.Text & vbCrLf & _
            " already exists. Copy over old file?", _
              MsgBoxStyle.OKCancel) = MsgBoxResult.Cancel Then
        End If
    End If

    ' Get the size of the file to copy
    ' and calculate the number of times to loop
    ' the copy routine based on moving 256 bytes at a time
    Try
        lngFileSize = FileLen(txtSourceFile.Text)
        catch nofile as io.FileNotFoundException
        MsgBox(nofile.Message)
        Exit Sub
    End Try
    intBufferCount = lngFileSize / 256

    ' Open the source and destination files
    FileOpen(1, txtSourceFile.Text, OpenMode.Binary)
    FileOpen(2, txtTargetFile.Text, OpenMode.Binary)

    ' This routine loops until the entire file is copied
    Try
        For intLoopCtr = 1 To intBufferCount + 1
            FileGet(1, strInByte)
            FilePut(2, strInByte)
        Next intLoopCtr
    catch DiskFull as IO.FileLoadException
        MsgBox("Disk is Full, Cannot complete copy", MsgBoxStyle.Critical)
    Catch IOError As IO.IOException
        MsgBox("An IO error has occurred", MsgBoxStyle.Critical)
    Catch
        MsgBox("An unexpected Error has occurred", MsgBoxStyle.Critical)
    Finally
        FileClose(1)     ' Close file.
        FileClose(2)     ' Close file.
    End Try

    ' After the copy is complete close both files
    ' Inform the user that the function is complete
    MsgBox("Copy function complete", MsgBoxStyle.Information)
End Sub
